package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.IMaterielTypeDao;
import com.hy.erp.inventory.pojo.MaterielType;
import com.hy.erp.inventory.pojo.interfaces.IMaterielType;
import com.hy.erp.inventory.service.interfaces.IMaterielTypeService;

@ Name ( "materielTypeService" )
@ Scope ( ScopeType.STATELESS )
@ Stateless
public class MaterielTypeService extends AbstractBusinessService < IMaterielType > implements IMaterielTypeService
{

	@ Override
	public boolean addMaterielType (
										IMaterielType materielType )
	{



		if ( null == materielType )
		{
			return true ;
		}

		else
		{
			System.out
						.println ( "ssssssssssssssssssssssffffffffffffffffhghhhhhhhhhhhhhhhhhhhhhh" ) ;

			IMaterielTypeDao materielTypeDao =
												( IMaterielTypeDao ) this
																			.getDao ( IMaterielType.class ) ;

			return materielTypeDao
									.persist ( materielType ) ;
		}

	
	
	}

	@ Override
	public boolean modifyMaterielType (
										IMaterielType materielType )
	{



		if ( ( null == materielType )
				|| ( null == materielType
											.getIdentifier ( ) )
				|| ( materielType
									.getIdentifier ( )
									.trim ( )
									.length ( ) == 0 ) )
		{
			return true ;
		}
		else
		{

			IMaterielTypeDao materielTypeDao =
				( IMaterielTypeDao ) this
											.getDao ( IMaterielType.class ) ;


			if ( null == materielType )
			{
				throw new ArchitectureFoundationException (
															"修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}

			return ( materielTypeDao
									.merge ( materielType ) != null ) ;
		}

	
	
	}

	@ Override
	public Integer removeMaterielType (
										String [ ] materielTypeIds )
	{

		if ( ( null == materielTypeIds )
				|| ( materielTypeIds.length == 0 ) )
		{
			return new Integer (
									0 ) ;
		}
		else
		{


			IMaterielTypeDao materielTypeDao =
												( IMaterielTypeDao ) this
																			.getDao ( IMaterielType.class ) ;

			return materielTypeDao
									.remove ( materielTypeIds ) ;
		}
	
	}

	@ Override
	public String [ ] addMaterielType (
										Object [ ] materielType )
	{


		if ( null == materielType )
		{
			return null ;
		}

		else
		{

			IMaterielTypeDao materielTypeDao =
												( IMaterielTypeDao ) this
																			.getDao ( IMaterielType.class ) ;

			MaterielType[] materielTypes=new MaterielType[materielType.length];
						for(int i=0;i<materielType.length;i++)
						{
							MaterielType materielType2=( MaterielType ) materielType[i];
							materielTypes[i]=materielType2;
						}
						return materielTypeDao
						                .persist ( materielTypes ) ;
			
		}

	
	
	
	}

	@ Override
	public List < IMaterielType > getAllMaterielType ( )
	{

		IMaterielTypeDao materielTypeDao =
											( IMaterielTypeDao ) this
																		.getDao ( IMaterielType.class ) ;

		return materielTypeDao
								.find ( ) ;
	}

	@ Override
	public String [ ] modifyMaterielType (
											Object [ ] materielType )
	{



		if ( null == materielType )
		{
			return null ;
		}

		else
		{

			IMaterielTypeDao materielTypeDao =
												( IMaterielTypeDao ) this
																			.getDao ( IMaterielType.class ) ;

			MaterielType[] materielTypes=new MaterielType[materielType.length];
						for(int i=0;i<materielType.length;i++)
						{
							MaterielType materielType2=( MaterielType ) materielType[i];
							materielTypes[i]=materielType2;
						}
						return materielTypeDao
						                .merge  ( materielTypes ) ;
			
		}

	
	
	
	
	}
}
